package cn.sunzq.springdata.elasticsearch.demo.base.response;

import lombok.Data;
import lombok.experimental.Accessors;

import java.util.LinkedList;
import java.util.List;

@Data
@Accessors(chain = true)
public class ResponseMessage {

	public Integer code;
	public String message;

	public ResponseMessage(){

	}

	public ResponseMessage(BizErrorEnum bizErrorEnum) {
		this.code = bizErrorEnum.getErrorCode();
		this.message = bizErrorEnum.getErrorMessage();
	}

	public ResponseMessage(int code,String message){
		this.code = code;
		this.message = message;
	}


	public static List<ResponseMessage> singleMessage(BizErrorEnum bizErrorEnum){
		List<ResponseMessage> messageList = new LinkedList<>();
		messageList.add(new ResponseMessage(bizErrorEnum));
		return messageList;
	}

	public static List<ResponseMessage> singleMessage(BizException bizException){
		List<ResponseMessage> messageList = new LinkedList<>();
		messageList.add(new ResponseMessage(bizException.getErrorCode(), bizException.getErrorMessage()));
		return messageList;
	}

	public static List<ResponseMessage> singleMessage(Exception exception){
		List<ResponseMessage> messageList = new LinkedList<>();
		messageList.add(new ResponseMessage().setMessage(exception.toString()));
		return messageList;
	}

	public static List<ResponseMessage> secMessage(int code,String message){
		List<ResponseMessage> messageList = new LinkedList<>();
		messageList.add(new ResponseMessage(code,message));
		return messageList;
	}
	
}
